﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DSPara
{
    public class OffsetPara
    {
        public string Section { get; private set; }

        public OffsetPara(string _section)
        {
            Section = _section;
        }

        public List<Entity_Offset_Chan> ListOffset { get; set; }

        internal void Init(Entity_Offset entity_Offset)
        {
            ListOffset = entity_Offset?.ListOffset;
        }

        /// <summary>
        /// 这里的index是从1开始的
        /// </summary>
        /// <param name="index"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public double GetOCV(int index, double data)
        {
            if (ListOffset != null)
            {
                var offset = ListOffset.FirstOrDefault(x => x.AtChan == index);
                if (offset != null)
                {
                    return data + offset.OCV;
                }
            }
            return data;
        }

        /// <summary>
        /// 这里的index是从1开始的
        /// </summary>
        /// <param name="index"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public double GetIR(int index, double data)
        {
            if (ListOffset != null)
            {
                var offset = ListOffset.FirstOrDefault(x => x.AtChan == index);
                if (offset != null)
                {
                    return data + offset.IR;
                }
            }
            return data;
        }
    }
}